blob: e8084cbef8800861533eea250a81ff86732ef6ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import Seo from '@/core/components/Seo'
import { getIdFromSlug } from '@/core/utils/slug'
import productApi from '@/lib/product/api/productApi'
import dynamic from 'next/dynamic'
const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'))
const Product = dynamic(() => import('@/lib/product/components/Product/Product'))
export async function getServerSideProps(context) {
const { slug } = context.query
let product = await productApi({ id: getIdFromSlug(slug) })
if (product?.length == 1) {
product = product[0]
const regexHtmlTags = /(<([^>]+)>)/gi
const regexHtmlTagsExceptP = /<\/?(?!p\b)[^>]*>/g
if (product.description.replace(regexHtmlTags, ' ').trim() == '') {
product.description = ''
}
product.description = product.description.replace(regexHtmlTagsExceptP, ' ')
product.description = product.description.trim()
}
return { props: { product } }
}
export default function ProductDetail({ product }) {
return (
<BasicLayout>
<Seo title={product?.name} />
<Product product={product} />
</BasicLayout>
)
}
|